package com.shipwe.loans.ui.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.recyclerview.widget.RecyclerView
import com.shipwe.adapter.ShipweRecyclerViewAdapter
import com.shipwe.adapter.ShipweViewHolderHelper
import com.shipwe.loans.R
import org.json.JSONObject

/**
 * Shipwe
 * @Author wwdeng
 * @CreateTime: 2024/11/15 17:07
 * @Annotation：积分明细列表
 */
class UserPointsAdapter(recyclerView: RecyclerView?) : ShipweRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.activity_points_item) {

    override fun setItemChildListener(helper: ShipweViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    @SuppressLint("SetTextI18n")
    override fun fillData(helper: ShipweViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.pointsTitle,model.optString("changeInfo"))
        helper.setText(R.id.pointsTime,model.optString("createTime"))

        val textPoint = helper.getTextView(R.id.pointsCount)
        val changeScore = model.optInt("changeScore")
        if (changeScore > 0){
            textPoint.text = "+ $changeScore"
            textPoint.setTextColor(Color.parseColor("#FF222222"))
        } else {
            textPoint.text = "$changeScore"
            textPoint.setTextColor(Color.parseColor("#FFFF3E55"))
        }
    }
}